ccc96b
@@ -810,11 +810,18 @@
public Object process(Node nd, Stack<Node> stack, NodeProcessorCtx ctx,
         ArrayList<String> newOutputColumnNames = new ArrayList<String>();
         ArrayList<ColumnInfo> rs_oldsignature = op.getSchema().getSignature();
         ArrayList<ColumnInfo> rs_newsignature = new ArrayList<ColumnInfo>();
+        // The pruning needs to preserve the order of columns in the input schema
+        Set<String> colNames = new HashSet<String>();
         for (FieldNode col : cols) {
-          int index = originalOutputColumnNames.indexOf(col.getFieldName());
-          newOutputColumnNames.add(col.getFieldName());
-          newColList.add(originalColList.get(index));
-          rs_newsignature.add(rs_oldsignature.get(index));
+          colNames.add(col.getFieldName());
+        }
+        for (int i = 0; i < originalOutputColumnNames.size(); i++) {
+          String colName = originalOutputColumnNames.get(i);
+          if (colNames.contains(colName)) {
+            newOutputColumnNames.add(colName);
+            newColList.add(originalColList.get(i));
+            rs_newsignature.add(rs_oldsignature.get(i));
+          }
         }
         op.getSchema().setSignature(rs_newsignature);
         conf.setColList(newColList);
